package com.ptu.mapper;

import com.github.pagehelper.Page;
import com.ptu.dto.CommentDTO;
import com.ptu.dto.CommentUpdateDTO;
import com.ptu.entity.Comment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CommentMapper {

    //添加评论
    @Insert("insert into comment(user_id, order_id,content,rating,images,is_anonymous,create_time,update_time) values(#{userId},#{orderId},#{content},#{rating},#{images},#{isAnonymous}, NOW(), NOW())")
    void addComment(Comment comment);

    //删除评论
    @Delete("delete from comment where id=#{id}")
    void deleteComment(Integer id);

    //修改评论
    @Update("update comment set content=#{content},rating=#{rating},images=#{images},is_anonymous=#{isAnonymous},update_time=NOW() where order_id=#{orderId}")
    void updateComment(CommentDTO commentDTO);

    Page<Comment> getCommentList(Integer rating, Integer isAnonymous);

    @Select("select * from comment where user_id=#{userId}")
    List<Comment> getMyCommentList(Integer userId);

    @Select("select * from comment where order_id=#{orderId}")
    Comment getCommentById(Long orderId);
}
